OOP  - Assignment 3

Topic:              The Friendship Between a Dog and His Owner

Points:             25

Due:                   1-31-2003

Instructor:         Dana Steil

 


Expected new material:


Friend Classes

Member Initialization List

  

General Overview:

You will be creating two classes, one for a dog another for a dog’s owner.  Every CdogsOwner has a dog as a data member.  A CDog can also be created on its own.

 

Discription of CDog: Dog.h, and Dog.cpp

 

  1. Use complier directives to avoid redefinition problems with the CDog class.
  2. Extend friendship to the CDogOwner.
  3. A dog must have a name to be created.  No unnamed dogs are allowed. (Hint: Use the constructor to enforce this.)
  4. Dogs can Bark and Scratch for anyone who tells him to.  (Hint: That means they are void public methods.)   You can be as creative or uncreative as you wish in representing the dog barking and scratching.  It must be obvious what dog is doing the barking and scratching.
  5. A dog has the private properties Name and OnLeash.  Name is a string.  OnLeash is a Boolean. 
  6. Dogs can Byte and Rollover, but these are void private methods.  Follow the same standards as bark and scratch.

 

Discription of CDogOwner: DogOwner.h, and DogOwner.cpp

1.   Use complier directives to avoid redefinition problems with the CDog class.

  1. A dog owner must have a name and the name of his dog to be created.  No unnamed dog owners or dogs are allowed. (Hint: Use the constructor to enforce this.)  Use the member initialization list of the CdogOwner to initialize the CDog via its constructor
  2. DogOwners have four public methods all of which deal with leashing and unleashing dogs.

a)      void PutLeashOn(); Sets the OnLeash property of its dog to true;

b)     void TakeLeashOff(); Sets the OnLeash property of its dog to false; and causes the dog to roll over.

c)      void PutLeashOn(CDog& Dog); Causes the strange dog to bark and byte.

d)     void TakeLeashOff(CDog& Dog); Calls the Steal Dog utility function.

  1. A dog owner has the private properties Name and Dog.  Name is a string. Dog is a CDog.
  2. Dog owners have a utility function void StealDog(CDog& Dog)  which is used when they are unleashing a strange dog. 

a)      Do not change any properties of the ower or the owner’s dog.

b)     Inform the user that an owner (by name) is stealing a dog (by name).

c)      Ask the user for a new name for the stolen dog and change its name.     

 

 


 

Example Test Program Filename: Assignment3.cpp

Write your own!!

 

#include "Dog.h"

#include "Owner.h"

#include <iostream>

 

using std::cout;

using std::endl;

 

 

void main()

{

       CDogOwner Bob("Bob", "Sammy");

       CDog Rover("Rover");

       CDog Duke("Duke");

 

       Rover.Bark();

 

       Rover.Scratch();

 

       Bob.PutLeashOn();

       Bob.TakeLeashOff();

 

       Bob.PutLeashOn(Rover);

       Bob.TakeLeashOff(Duke);

 

       Duke.Bark();

 

}

 

     

results:

 

The dog Rover is barking.

The dog Rover is scratching.

The dog Sammy is rolling over.

The dog Rover is barking.

The dog Rover just bit you.

Bob is stealing Duke

What whould you like your stolen dog's name to be:

Bell

The dog Bell is barking.

Press any key to continue